<template>
  <div class="app-container">
    <!-- 查询结果 -->
    <el-table v-loading="listLoading" :data="list" element-loading-text="正在查询中。。。" border fit highlight-current-row>

      <el-table-column align="center" width="100px" label="序号" prop="id"/>

      <el-table-column align="center" min-width="100px" label="积分" prop="credit"/>

      <el-table-column align="center" min-width="200px" label="描述" prop="description"/>

      <el-table-column align="center" min-width="100px" label="日期" prop="time"/>

    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />

  </div>
</template>

<script>
import { listCredit } from '@/api/creditHistory'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination

export default {
  name: 'CreditHistory',
  components: { Pagination },
  data() {
    return {
      list: undefined,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        name: undefined,
        code: undefined,
        userId: -1
      },
      downloadLoading: false
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      if (this.$route.query.id == null) {
        return
      }
      const userId = this.$route.query.id
      this.listQuery.userId = userId
      this.listLoading = true
      listCredit(this.listQuery).then(response => {
        this.list = response.data.data.items
        this.total = response.data.data.total
        this.listLoading = false
      }).catch(() => {
        this.list = []
        this.total = 0
        this.listLoading = false
      })
    }
  }
}
</script>
